home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / wtjmarch.zip / HATCH.ZIP / LIANA.TXT < prev    next >
Text File  |  1992-02-21  |  2KB  |  70 lines

  1. FIGURE 1: Liana Example of Encapsulation.
  2.  
  3. // EDITWIND.L - Text editor window.
  4.  
  5. class editwindow: window {
  6.   window ed;
  7.   void editwindow ()
  8.     {
  9.       window ();
  10.       this.home;
  11.       this << (ed = new edittext);
  12.       ed.multiline = true;
  13.       ed.hscroll = true;
  14.       ed.vscroll = true;
  15.       ed.autohscroll = true;
  16.       ed.autovscroll = true;
  17.       resize_control ();
  18.       ed.show;
  19.       got_focus ();
  20.     }
  21.   void editwindow (string title)
  22.     {
  23.       editwindow ();
  24.       this.text = title;
  25.     }
  26.   void got_focus () {if (ed) ed.have_focus = true;}
  27.   void resized (int width, int height) {resize_control ();}   void
  28. resize_control ()
  29.     {
  30.       update_status_line_position ();
  31.       if (ed) {
  32.         ed.width = this.width + 1;
  33.         ed.height = this.height + 1;
  34.         ed.x = -1;
  35.         ed.y = -1;
  36.     }
  37.   }
  38.   bool status_line_enabled_set (bool status_line_enabled)
  39.   {
  40.     window::status_line_enabled_set (status_line_enabled);
  41.     resize_control ();
  42.   }
  43. };
  44.  
  45. // FILEWIND.L - Window that displays contents of a text file.
  46.  
  47. class filewindow: textwindow {
  48.   public:
  49.     string path;
  50.   void filewindow (string path)
  51.   {
  52.     // Initialize the text window.
  53.     textwindow (title (path));
  54.     // Try to open the file.
  55.     if (! (file f = fopen (path))) {
  56.       error ("Unable to open file: "+path);
  57.       exit (3);
  58.       }
  59.     // Read the contents of the file.
  60.     while (string line = f.readline)
  61.       this << line;
  62.     fclose (f);
  63.     // Display the text read from the file.
  64.     this.first_row = 0;
  65.     show ();
  66.     // Remember the path.
  67.     filewindow::path = path;
  68.   }
  69. };
  70.